home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * Copy file(s) with TwinExpress from DOpus.
- *
- * (c) 1994 by K.P. van Beem (2:280/464.2, patrick.van.beem@aobh.xs4all.nl)
- *
- * Based on the DOpusLhaARexx package by Geoff Seeley (but you can better
- * use GuiArc in stead of DOpus and a script, to deal with archives)
- *
- ------ some mods by Ray Abram
- -last update 24 / 12 / 94
-
- - properly handle Twin Dirs <-> DOpus dirs
- - if a Dir is copied, then the dir is created,
- and the files then copied into the directory...
-
- - All Directories are also recursed into...
- - If Dopus is used as the Destination, then Dopus will be told to
- re-scan the dir.
-
- - Add Wait option on REXX call command line
- - this option (specified on the Command line) will force DOpus to wait
- for each file to be copied before telling TWIN to copy the next...
- - eg rexx:dopus/CopyFile.rexx WAIT
- - TRUE or False must be entered if you want to use "SAVEAS" option
- - will report an error if the destination cannot fit the sent file
- - when Dirs are copied, then twin reports as each file is copied
- - so show these files as they are copied...
-
- - Add "Copy AS" ability
- - option called "COPYAS" will prompt for a new name
-
- - Add a move command
- - option call "DELETE"
- - deletes the source after doing a copy
- - *** note that the source window doen't get updated, thus looking like
- a copy operation has been performed... (but the move has worked)
-
- - A bit of recognition on file coping. Now states Local or Remote on the
- status line...
- */
-
- /* trace results with user ENTER key to execute each command */
- Trace ?Results
-
- DOpusPort = 'DOPUS.1'
-
- if ~show(l,"rexxsupport.library") then
- call addlib("rexxsupport.library",0,-30,0)
- if showlist('Ports', DOpusPort) = 0 then do
- say 'Directory Opus Arexx port not found. Aborting.'
- call CleanUp
- end
-
- address 'DOPUS.1'
- options results
-
- /* get parameters and default all to off*/
- parse arg params
- Wait=False
- CopyAs=False
- Delete=False
-
- /* now scan the options */
- do wrd = 1 to words(params)
- temp = word(params, wrd)
-
- /*see if wait flag is here */
- if upper(temp) = 'WAIT' then
- Wait=True
-
- /* see if copy flag is here */
- if upper(temp) = 'COPYAS' then
- CopyAs=True
-
- /* see if delete flag is here */
- if upper(temp) = 'DELETE' then
- Delete=True
-
- end
-
- /* setup DOpus window and tell user what's happening */
- Busy on
- TopText "Copying selected files..."
-
- /* Get the destination path */
- OtherWindow
- 'Status 6 -1'
- GetEntry Result
- ToPath = Result
- Dopus=False
- if left(ToPath,1) = '*' then do
- ToPath = SubStr(ToPath,2)
- DoReread='TRUE'
- end
- else do
- 'Status 13 -1'
- ToPath = result
- if right(ToPath,1) = '/' then
- ToPath = left(ToPath,length(ToPath)-1) /* strip the / that DOPus put there */
-
- Dopus = True
-
- if ToPath = '' then do
- TopText "No destination directory selected ???"
- call CleanUp
- end
- DoReread='FALSE'
- end
-
- OtherWindow
-
- /* Get the current path and do file-copy, depending on the */
- /* type of path (Twin-path or normal path) */
- 'Status 6 -1'
- GetEntry Result
- FilePath = Result
-
- /* Twin-way (from twin to Dopus or from Twin to Twin)*/
- if left(FilePath,1) = '*' then do
- FilePath = SubStr(FilePath,2)
-
- /* change to the source and destination dirs and remember local/remote bit */
- SA = EnterDir(FilePath)
- DA = EnterDir(ToPath)
-
- /*ensure that user only copies local -> remote or vise versa*/
- if SA = '~' & DA = '~' then do
- Request "Cannot Copy Remote -> Remote (Only Local <-> Remote !!)"
- call CleanUp
- end
- if SA = '' & DA = '' then do
- Request "Cannot Copy Local -> Local (Only Local <-> Remote !!)"
- call CleanUp
- end
-
- GetSelectedAll
- SelectedEntries = result
- if SelectedEntries = 'RESULT' then do
- TopText "No Files/Dirs are selected."
- call CleanUp
- end
- NumberOfEntries = words(SelectedEntries)
- do EntryNumber = 1 to NumberOfEntries
- Index = word(SelectedEntries, EntryNumber)
- SelectEntry Index 0 1
- GetEntry Index+1
- Entry = result
- ScrollToShow '"'Entry'"'
- File = strip(left(Entry,25))
-
- if CopyAs = True then do
- getstring '"Enter New name for Moved File :"' File
- File2 = Result
- if File2="" then do
- File2 = File
- Request "No Rename Performed... (keeping" File2 ")"
- end
- end
- else
- File2 = File
-
- ToFile = Quote(DA || File2)
- File = Quote(SA || File)
-
- if words(File) > 1 then
- Request "Spaces in File/Dir Names are not Allowed !!"
- else do
-
- /* if source is a directory, then make a dir. in dest. */
- extra = ''
- Directory = upper(substr(Entry,26,1))
- if Directory = 'D' then do
- address command 'echo >PPipe: md' File
- extra = ' SUBDIR'
- end
-
- /* keep user updated with the file being copied */
- if DA ~= '~' then
- TopText "Copying Remote To Local " File
- else
- TopText "Copying Local to Remote " File
-
- /*tell TWIN to copy the File... and then put something into the Queue:*/
- address command 'echo >PPipe: copy' File ToFile Extra
- address command 'echo >PPipe: echo END-LIST'
- address command 'echo >PPipe: help'
-
- /* if user wanted to wait between files...*/
- if Wait = True then
- if open(PipeList, "QUEUE:Twin", 'R') then do
- if extra = '' then
- call WaitForAFile
- else do
- test = ''
-
- /* received is for a normal copy, sent is for a copy as */
- do while ( (find(junk,"END-LIST") = 0) & (find(junk,"Error:") = 0) )
- junk = readln(PipeList)
- test = left(junk , 8, '')
- if ((test = "received") | (test = " sent ") | (test = " copied ")) then
- TopText "Copied file" word(junk, words(junk)) "..."
- end
-
- /*check for errors and show user the error*/
- fnd = find(junk,"Error:")
- if fnd > 0 then
- Request right(junk,length(junk)-wordindex(junk,fnd)+1)
- end
- close(PipeList)
- end
-
- /* if user wanted to delete files */
- if Delete = True then do
- TopText "Deleting" File "..."
-
- address command 'echo >PPipe: delete' File ' SUBDIR'
- address command 'echo >PPipe: help'
- if open(PipeList, "QUEUE:Twin", 'R') then do
- test = ''
- /* deleted is for a file just deleted */
- do while (test ~= "deleted")
- junk = readln(PipeList)
- test = right(junk , 7, '')
- end
- close(PipeList)
- end
- end
- end
- end
-
- if ((Dopus = True) & (Delete = False)) then do
- otherwindow
- ReScan
- otherwindow
- end
-
- end
-
- /* Normal way (dopus -> twin, Dopus -> Dopus)*/
- else do
-
- 'Status 13 -1'
-
- FilePath = result
- if FilePath = '' then do
- TopText "No Source directory selected. ??"
- call CleanUp
- end
-
- /*see if the destination is also a dopus dir */
- otherwindow
- 'Status 6 -1'
- GetEntry Result
- FP = Result
- otherwindow
- if left(FP,1) ~= '*' then do
- Busy off
- if CopyAs = True then do
- if Delete = True then do
- MoveAs
- end
- else do
- /* the CopyAs command is here, but doesn't seem to work !!?? */
- CopyAs
- end
- end
- else do
- if Delete = True then do
- Move
- end
- else do
- Copy
- end
- end
- call CleanUp
- end
-
- /* change to the source and destination dirs and remember local/remote bit */
- SA = EnterDir(FilePath)
- DA = EnterDir(ToPath)
-
- /*ensure that user only copies local -> remote or vise versa*/
- if SA = '~' & DA = '~' then do
- Request "Cannot Copy Remote -> Remote (Only Local <-> Remote !!)"
- call CleanUp
- end
- if SA = '' & DA = '' then do
- Request "Cannot Copy Local -> Local (Only Local <-> Remote !!)"
- call CleanUp
- end
-
- do loop=1 to 2
-
- /* copy Dirs on Pass 1 and Files on pass 2 */
- if loop=1 then do
- extra = ' SUBDIR'
- TopText "Copying Dirs"
- 'GetSelectedDirs "|" -1'
- end
- else do
- extra = ''
- TopText "Copying Files"
- 'GetSelectedFiles "|" -1'
-
- end
-
- /* do the following if some entries are selected */
- SelectedEntries = result
- if ~(SelectedEntries = 'RESULT') then do
- NumberOfEntries = CountWords(SelectedEntries)
- do EntryNumber = 1 to NumberOfEntries
- File = GetWord(EntryNumber, SelectedEntries)
- SelectFile File 0 1
- ScrollToShow '"'File'"'
-
- if CopyAs = True then do
- getstring '"Enter New name for Moved File :"' File
- File2 = Result
- if File2="" then do
- File2 = File
- TopText "No Rename Performed... "
- end
- end
- else
- File2 = File
-
- ToFile = Quote(DA || File2)
- File = Quote(SA || File)
-
- if words(ToFile) > 1 then do
- Request "Spaces in File/Dir Names are not Allowed !!"
-
- end
- else do
-
- if loop = 1 then
- address command 'echo >PPipe: md' ToFile
-
- /* keep user updated with the file being copied */
- if DA ~= '~' then
- TopText "Copying Remote To Local " File
- else
- TopText "Copying Local to Remote " File
-
- /* get twin to do the copy... */
- address command 'echo >PPipe: copy' File ToFile Extra
- address command 'echo >PPipe: echo END-LIST'
- address command 'echo >PPipe: help'
-
- /* if user wanted to wait between files...*/
- if Wait = True then
- if open(PipeList, "QUEUE:Twin", 'R') then do
- if extra = '' then
- call WaitForAFile
- else do
- test = ''
-
- /* received is for a normal copy, sent is for a copy as */
- do while ( (find(junk,"END-LIST") = 0) & (find(junk,"Error:") = 0) )
- junk = readln(PipeList)
- test = left(junk , 8, '')
- if ((test = "received") | (test = " sent ") | (test = " copied ")) then
- TopText "Copied file" word(junk, words(junk)) "..."
- end
-
- /*check for errors and show user the error*/
- fnd = find(junk,"Error:")
- if fnd > 0 then
- Request right(junk,length(junk)-wordindex(junk,fnd)+1)
- end
- close(PipeList)
- end
-
- /* if user wanted to delete files */
- if Delete = True then do
- address command 'echo >PPipe: delete' File ' SUBDIR'
- address command 'echo >PPipe: help'
- if open(PipeList, "QUEUE:Twin", 'R') then do
- test = ''
- /* deleted is for a deleted file */
- do while (test ~= "deleted")
- junk = readln(PipeList)
- test = right(junk , 7, '')
- end
- close(PipeList)
- end
- end
- end
- end
- end /* for */
- end /* if nothing is selected */
-
- if Dopus = True then do
- otherwindow
- ReScan
- otherwindow
- end
- end
-
- EndBit:
-
- TopText "Ready"
- 'DisplayDir -1'
- if ((DoReread = True) | (Dopus = True)) then do
- otherwindow
- address AREXX "Rexx:DOpus/ReRead.rexx"
- end
-
- if Delete = True then
- request "Please ReRead the Source Directory..."
-
- call CleanUp
-
- exit
-
- /*---------------------------------------------------------------------------*/
-
- CleanUp: /* Remove any files and exit */
- Busy off
- DopusToFront
- exit
- return
-
- /*---------------------------------------------------------------------------*/
-
- WaitForAFile:
- test = ''
- /* received is for a normal copy, sent is for a copy as */
- do while ((test ~= "received") & (test ~= " sent ") & (test ~= " copied ") & (test ~= "Error: D") & (test ~= "TWIN> Er"))
- junk = readln(PipeList)
- test = left(junk , 8, '')
- end
-
- /*check for errors and show user the error*/
- fnd = find(junk,"Error:")
- if fnd > 0 then do
- Request right(junk,length(junk)-wordindex(junk,fnd)+1)
- close(PipeList)
- call EndBit
- end
-
- return
-
- /*--------------------------------------------------------------------------*/
-
- Quote: procedure /* add quotes to string */
- parse arg string
- return '"'||string||'"'
-
- /*--------------------------------------------------------------------------*/
-
- GetWord: procedure /* get word from '|' separated string */
-
- parse arg number,words
-
- if(left(words,1) ~= '|') then
- words = '|'||words
- do i=1 to number
- idx = index(words, '|');
- words = substr(words, idx+1)
- end
- end = index(words, '|') - 1
- if words = "" then
- return ""
-
- ret_str = substr(words, 1, end)
- return ret_str
-
- /*--------------------------------------------------------------------------*/
-
- CountWords: procedure /* count words from '|' separated string */
-
- parse arg words
-
- count = 0
- idx = index(words, '|')
- do while idx ~= 0
- count = count + 1
- words = substr(words, idx+1)
- idx = index(words, '|')
- end
- return count
-
- /*--------------------------------------------------------------------------*/
-
- /* Cd into the sent Directory path
- - this is needed, as TWIN has a command parameter limit of 30 characters,
- and as we all know AmigaDos file & paths can easily go over this limit !!*/
-
- EnterDir: procedure
-
- parse arg Dev ':' Path
-
- /* get the 1st character to ddress the local or remote machine correctly */
- if left(Dev,1) = '~' then
- sbit = '~'
- else
- sbit = ''
-
- /* does the passed name have a DEVICE in it ? */
- if Dev ~= '' then
- address command 'echo >PPipe: cd' Dev || ':'
-
- do until (t2 = '')
- parse var Path t1 '/' t2
- path = t2
- if t1 ~= '' then
- address command 'echo >PPipe: cd' sbit || t1
- end
-
- return sbit
-